self.target_config(kind).ar.as_ref().map(|s| s.as_ref())
}
+ /// Get the list of cfg printed out from the compiler for the specified kind
+ pub fn cfg(&self, kind: Kind) -> &[Cfg] {
+ let info = match kind {
+ Kind::Host => &self.host_info,
+ Kind::Target => &self.target_info,
+ };
+ info.cfg.as_ref().map(|s| &s[..]).unwrap_or(&[])
+ }
+
/// Get the target configuration for a particular host or target
fn target_config(&self, kind: Kind) -> &TargetConfig {
match kind {
use std::sync::{Mutex, Arc};
use core::PackageId;
-use util::{CargoResult, Human, Freshness};
+use util::{CargoResult, Human, Freshness, Cfg};
use util::{internal, ChainError, profile, paths};
use super::job::Work;
}
}
+ let mut cfg_map = HashMap::new();
+ for cfg in cx.cfg(unit.kind) {
+ match *cfg {
+ Cfg::Name(ref n) => { cfg_map.insert(n.clone(), None); }
+ Cfg::KeyPair(ref k, ref v) => {
+ match *cfg_map.entry(k.clone()).or_insert(Some(Vec::new())) {
+ Some(ref mut values) => values.push(v.clone()),
+ None => { /* ... */ }
+ }
+ }
+ }
+ }
+ for (k, v) in cfg_map {
+ let k = format!("CARGO_CFG_{}", super::envify(&k));
+ match v {
+ Some(list) => { cmd.env(&k, list.join(",")); }
+ None => { cmd.env(&k, ""); }
+ }
+ }
+
// Gather the set of native dependencies that this package has along with
// some other variables to close over.
//
assert_that(build.cargo_process("bench"),
execs().with_status(0));
}
+
+#[test]
+fn cfg_env_vars_available() {
+ let build = project("builder")
+ .file("Cargo.toml", r#"
+ [package]
+ name = "builder"
+ version = "0.0.1"
+ authors = []
+ build = "build.rs"
+ "#)
+ .file("src/lib.rs", "")
+ .file("build.rs", r#"
+ use std::env;
+
+ fn main() {
+ let fam = env::var("CARGO_CFG_TARGET_FAMILY").unwrap();
+ if cfg!(unix) {
+ assert_eq!(fam, "unix");
+ } else {
+ assert_eq!(fam, "windows");
+ }
+ }
+ "#);
+ assert_that(build.cargo_process("bench"),
+ execs().with_status(0));
+}